/**
 * Copyright (c) 2011 eelpo.com
 * All rights reserved.
 */
package com.eelpo.cmmp.uac.pages.enterprise;

import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

import org.apache.wicket.extensions.markup.html.tree.table.ColumnLocation;
import org.apache.wicket.extensions.markup.html.tree.table.ColumnLocation.Alignment;
import org.apache.wicket.extensions.markup.html.tree.table.ColumnLocation.Unit;
import org.apache.wicket.extensions.markup.html.tree.table.IColumn;
import org.apache.wicket.extensions.markup.html.tree.table.PropertyRenderableColumn;
import org.apache.wicket.extensions.markup.html.tree.table.PropertyTreeColumn;
import org.apache.wicket.extensions.markup.html.tree.table.TreeTable;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.spring.injection.annot.SpringBean;

import com.eelpo.cmmp.core.exception.ServiceException;
import com.eelpo.cmmp.core.wicket.page.extensions.SerachContentWebPage;
import com.eelpo.cmmp.uac.dao.vo.Enterprise;
import com.eelpo.cmmp.uac.services.IEnterpriseManageService;
import com.eelpo.cmmp.uac.session.UACSession;

/**
 * <pre>
 * 
 * 企业管理
 * 
 * </pre>
 * 
 * @author <a href="mailto:Brian@eelpo.com">汪洪州</a>
 * @since 1.0
 */
public class EnterpriseManage extends SerachContentWebPage<Enterprise> {

	@SpringBean
	private IEnterpriseManageService enterpriseManageService;

	/**
	 * @param title
	 */
	public EnterpriseManage() {
		super("企业管理", new Enterprise());
	}

	@Override
	public Panel renderSearchPanel(String id) {
		return new EnterpriseSearchPanel(id, getParameter());
	}

	@Override
	public Panel renderSearchContentPanel(String id) {

		DefaultTreeModel treeModel = null;

		try {
			treeModel = enterpriseManageService.getEnterprises(UACSession.get().getUserId());
		} catch (ServiceException e) {
			treeModel = new DefaultTreeModel(new DefaultMutableTreeNode());
		}

		IColumn columns[] = new IColumn[] { new PropertyTreeColumn(new ColumnLocation(Alignment.LEFT, 30, Unit.PERCENT), "企业名称", "userObject.name"),
				new PropertyRenderableColumn(new ColumnLocation(Alignment.LEFT, 10, Unit.PERCENT), "联系人", "userObject.contact"),
				new PropertyRenderableColumn(new ColumnLocation(Alignment.LEFT, 10, Unit.PERCENT), "联系号码", "userObject.phone"),
				new PropertyRenderableColumn(new ColumnLocation(Alignment.LEFT, 10, Unit.PERCENT), "企业序列", "userObject.index"),
				new PropertyRenderableColumn(new ColumnLocation(Alignment.LEFT, 10, Unit.PERCENT), "企业状态", "userObject.status.label"),
 };

		TreeTable entityTree = new TreeTable(id, treeModel, columns);
		entityTree.setRootLess(true);
		entityTree.getTreeState().setAllowSelectMultiple(false);
		return entityTree;
	}
}
